// import { reject, resolve } from 'core-js/fn/promise'
import axios from 'axios'
export const addGoods = (url, data) => {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest()
    xhr.open('post', url)
    xhr.send(data)

    xhr.onload = () => {
      if (xhr.status === 200) {
        resolve(xhr.responseText)
      } else {
        reject(xhr)
      }
    }
    xhr.onerror = err => {
      reject(err)
    }
  })
}
// 请求用户信息
export const customs = url => {
  return axios.get(url)
}
// 请求速递员信息
export const express = url => {
  return axios.get(url)
}
// 主页请求商品信息
export const items = url => {
  return axios.get(url)
}

// 修改购物车
export const editShopCart = (url, data) => {
  return axios.post(url, { data })
}

// 用户登录验证
export const login = (url, params) => {
  return axios.get(url, { params })
}

// 用户注册
export const userRegiration = (url, data) => {
  return axios.post(url, { data })
}

// 用户登录
export const userLogin = (url, params) => {
  return axios.get(url, { params })
}

// 获取选中商品
export const getGoods = (url, params) => {
  return axios.get(url, params)
}

// 将商品加入购物车
export const addShoppingCart = (url, data) => {
  return axios.post(url, { data })
}

// 请求购物车数据
export const getShoppingCart = (url, params) => {
  return axios.get(url, { params })
}

// 获取地址
export const getAddress = (url, params) => {
  return axios.get(url, { params })
}

// 修改地址
export const modifyAddress = (url, data) => {
  return axios.post(url, { data })
}

// 提交订单
export const order = (url, data) => {
  return axios.post(url, { data })
}

// 成为速递员
export const isDelivery = (url, params) => {
  return axios.get(url, { params })
}

export const userInfo = (url, params) => {
  return axios.get(url, { params })
}

// 获取订单
export const getOrder = (url, params) => {
  return axios.get(url, { params })
}

// 确认收货
export const received = (url, params) => {
  return axios.get(url, { params })
}

// 速递员接单
export const chosenOrder = (url, params) => {
  return axios.get(url, { params })
}

// 搜索商品
export const searchitems = (url, params) => {
  return axios.get(url, { params })
}

// 管理员登录
export const adminLogin = (url, params) => {
  return axios.post(url, { params })
}

export const pagegoods = (url, params) => {
  return axios.get(url, { params })
}

export const delGoods = (url, data) => {
  return axios.post(url, { data })
}
